# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=atom-editor
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=r18372.d4f7e71
pkgrel=2
pkgdesc='Cross-platform desktop application shell (mingw-w64)'
source=("${_realname}-${CARCH}"::"git+https://github.com/atom/atom#branch=master")
arch=('any')
url='https://atom.io'
license=('MIT')
options=()
sha256sums=('SKIP')
depends=("${MINGW_PACKAGE_PREFIX}-nodejs")
makedepends=("${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "git")

pkgver() {
  cd "$srcdir"/${_realname}-${CARCH}
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "$srcdir"/${_realname}-${CARCH}
#  git am "$srcdir"/0001-python-python2.patch
#  git am "$srcdir"/0002-Add-ninja-option.patch
}

#build() {
#  cd "$srcdir"/${_realname}-${CARCH}
#  export GYP_GENERATORS=ninja
## Downloads atl, directxsdk, vs2012_crt.
##  ./script/update.py
#  ./script/build --verbose --force
#}

package() {
  plain "Currently, attempting to make a log fails!"
  plain " so for now, please call without -L option"

  cd "$srcdir"/${_realname}-${CARCH}

  export PYTHON=python2
  export INSTALL_PREFIX="${pkgdir}${MINGW_PREFIX}"
  export JANKY_SHA1=$_gitref
  export JANKY_BRANCH=$_gitbranch

  script/build --install-dir="${INSTALL_PREFIX}"
  script/grunt install

  patch "${INSTALL_PREFIX}/bin/atom" < "$srcdir/atom-python.patch"

  sed -e "s/<%= description %>/$pkgdesc/" \
    -e "s|<%= installDir %>/share/atom/atom|/usr/bin/atom|"\
    -e "s|<%= iconName %>|atom|"\
    resources/linux/Atom.desktop.in > resources/linux/Atom.desktop
  install -Dm644 resources/linux/Atom.desktop "${INSTALL_PREFIX}/share/applications/Atom.desktop"

  install -Dm644 resources/atom.png "${INSTALL_PREFIX}/share/pixmaps/atom.png"
  install -Dm644 LICENSE.md "${INSTALL_PREFIX}/share/licenses/${_realname}/LICENSE.md"
}

sha256sums=('SKIP')
